package weixinOperator

import (
	"t11Lib/t11Errors"
	"t11Lib/t11Http"
)

type JssdkTickerSupplier interface {
	Ticket() (string, error)
}
type JssdkTicketServerByOther struct {
	FetchUrl   string
	TicketPath string
}

func (self *JssdkTicketServerByOther) Ticket() (string, error) {
	obj, err := t11Http.GetJson(self.FetchUrl)
	if err != nil {
		return "", err
	}
	val := obj.Get(self.TicketPath)
	if !val.Exists() {
		return "", t11Errors.New("获取jsticket失败")
	}
	if val.String() == "" {
		return "", t11Errors.New("非法的jsticket")
	}
	return val.String(), nil
}

//第三方的AccessTokenServer
type AccessTokenServerByOther struct {
	FetchUrl        string
	AccessTokenPath string
}

func (self AccessTokenServerByOther) Token() (string, error) {
	obj, err := t11Http.GetJson(self.FetchUrl)
	if err != nil {
		return "", err
	}
	val := obj.Get(self.AccessTokenPath)
	if !val.Exists() {
		return "", t11Errors.New("获取AccessToken失败")
	}
	if val.String() == "" {
		return "", t11Errors.New("非法的AccessToken")
	}
	return val.String(), nil
}
func (self AccessTokenServerByOther) RefreshToken(curToken string) (string, error) {
	return "", nil
}
func (self AccessTokenServerByOther) IID01332E16DF5011E5A9D5A4DB30FED8E1() {}
